package org.csmzxy.class2333;

class AgeException extends Exception{
    public AgeException(String message){
        super(message);
    }
}
public class Example26 {
    //定义一个保存年龄的方法saveAge()
    public static void saveAge(int age) throws AgeException{
        if(age>0&&age<150){
            System.out.println("年龄被保存成功:"+age);
        }else{
            //抛出异常
            throw new AgeException("您输入的年龄不合法！");
        }
    }
    public static void main(String[]args){
        try{
            saveAge(125);
        }catch (AgeException e){
            System.out.println(e.getMessage());
        }
    }
}
